// 257.二叉树的所有路径
package Leetcode_Second_Brush;

import java.util.ArrayList;
import java.util.List;

public class Solution257 {
    public List<String> binaryTreePaths(TreeNode root) {
        List<String> result = new ArrayList<>();
        if (root == null)
            return null;
        else if (root.left == null && root.right == null)
            result.add(String.valueOf(root.val));
        else {
            List<String> left = binaryTreePaths(root.left);
            List<String> right = binaryTreePaths(root.right);
            if (left != null) {
                for (String l : left)
                    result.add(root.val + "->" + l);
            }
            if (right != null) {
                for (String r : right)
                    result.add(root.val + "->" + r);
            }
        }
        return result;
    }
}
